package org.acghub.config;

/**
 * @Desc
 * @Author miyuki4j
 * @Date 2025/7/24/星期四 16:44
 * @Version 1.0
 */
public abstract class AbstractConf<ID extends Comparable<ID>> implements Conf<ID> {

    @Override
    public void load(TableDataRow row) {
        ConfClassManager.ConfClass confClass = ConfClassManager.getConfClass(this.getClass());
        for (TableDataCell cell : row) {
            ConfClassManager.ConfField confField = confClass.getField(cell.getColumnName());
            if (confField != null) {
                try {
                    confField.setValue(this, confField.instance(cell.getValue()));
                } catch (Exception e) {
                    String errMsg = String.format("data load error, table=%s, row=%s, columnName=%s, value=%s", getClass().getName(), row.getRow(), cell.getColumnName(), cell.getValue());
                    throw new TableDataImportException(errMsg, e);
                }
            }
        }
    }
}
